<template>
    <div class="container">
        <!-- <Transition> -->
        <addMedicalProductClassify ref="addMedicalProductClassify" />
        <importFileView ref="importFileView" />
        <!-- </Transition> -->
        <div class="main">
            <div class="header felx">
                <div class="header_l flex">
                    <div class="header_btn flex" @click="addHandle">
                        <img src="../../assets/room_add_icon.png" style="width: 13px;height: 13px;margin-right: 0;" />
                        <p>新建物资分类</p>
                    </div>
                    <div class="header_btn flex" style="background-color: #fff; color: #666666;"
                        v-loading.fullscreen.lock="fullscreenLoading" @click="exportHandle">
                        <img src="../../assets/MedicalProductAssets_icon2.png">
                        <p>导出报表</p>
                    </div>
                    <div class="header_btn flex" style="background-color: #fff; color: #666666;" @click="importHandle">
                        <img src="../../assets/MedicalProductAssets_icon1.png">
                        <p>批量导入</p>
                    </div>
                    <div class="header_btn flex" style="background-color: #fff; color: #666666;"
                        @click="active = !active">
                        <el-icon>
                            <Switch />
                        </el-icon>
                        <p>切换视图</p>
                    </div>
                </div>
                <div class="header_r flex">
                    <div class="serachBox flex">
                        <div class="flex">
                            <p>物资名称</p>
                            <!-- <el-icon>
                                <ArrowDown />
                            </el-icon> -->
                        </div>
                        <input type="text" v-model="nameValue">
                        <button @click="getList">搜索</button>
                    </div>
                </div>
            </div>
            <div class="borderBox">
                <!-- <div class="borderTop flex">
                    <div class="workList"> 
                    </div>
                    <div class="flex">
                        <div class="borderTop_btn" @click="active = !active">
                            <el-icon>
                                <Switch />
                            </el-icon>
                            <p style="margin-left: 10px;">切换视图</p>
                        </div>
                    </div>
                </div> -->
                <Transition name="slide-up">
                    <div class="table_box">
                        <div class="tabBox" v-for="item in list" v-if="active">
                            <div class="tabHeader flex">
                                <p>{{ item.name }}</p>
                                <img src="../../assets/index_next_icon.png" alt="">
                            </div>
                            <div class="tab_row">
                                <div class="flex" style="align-items: flex-start;">
                                    <p class="tabName"><span></span>描述</p>
                                    <p class="tabContent">{{ item.description }}</p>
                                </div>
                            </div>
                            <div class="tab_btnBox">
                                <button class="editBtn" @click="editHandle(item.id)">编辑</button>
                                <button class="detailBtn" @click="delHandle(item.id)">删除</button>
                            </div>
                        </div>

                        <el-table v-else :data="list" border style="width: 100%;" scrollTo
                            :row-class-name="tableRowClassName" :header-cell-style="headerCellStyle"
                            :row-style="tableRowStyle">
                            <el-table-column prop="id" label="序号" width="150">
                                <template #header>
                                    <div class="header_icon">
                                        <span>序号</span>
                                        <el-icon class="rotate">
                                            <MoreFilled />
                                        </el-icon>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column prop="name" label="分类名称">
                                <template #header>
                                    <div class="header_icon">
                                        <span>分类名称</span>
                                        <el-icon class="rotate">
                                            <MoreFilled />
                                        </el-icon>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column prop="description" label="描述信息">
                                <template #header>
                                    <div class="header_icon">
                                        <span>描述信息</span>
                                        <el-icon class="rotate">
                                            <MoreFilled />
                                        </el-icon>
                                    </div>
                                </template>
                            </el-table-column>

                            <el-table-column label="操作" width="200px" fixed="right">
                                <template style="display: block" #default="scope">
                                    <el-button class="edit_btn" size="small" type="success" style="margin-right: 10px;"
                                        @click="editHandle(scope.row.id)">编辑
                                    </el-button>
                                    <el-button class="del_btn" size="small" type="danger"
                                        @click="delHandle(scope.row.id)">删除
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </Transition>

                <div style="margin-top: 10px" class="pageBox flex">
                    <el-config-provider :locale="locale">
                        <el-pagination :total="total" :current-page="page" :page-size="pageSize" background
                            layout="prev, pager, next, sizes" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                            @size-change="changePageSize" @current-change="changeCurrentPage" />
                        <div class="flex">
                            <p>第 {{ page }} 条</p>
                            <p>共 {{ total }} 条数据</p>
                        </div>
                    </el-config-provider>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { httpService } from "@/utils/httpService";
import { ElConfigProvider, ElMessage, ElMessageBox, ElLoading } from "element-plus";
import { MoreFilled, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown, Plus, Switch } from "@element-plus/icons-vue";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import addMedicalProductClassify from "../../components/medicalProduct/addMedicalProductClassify.vue"
import importFileView from "../../components/medicalProduct/importFileView.vue"

export default {
    name: "MedicalProductLogin",
    components: { ElMessage, addMedicalProductClassify, ElLoading, Switch, importFileView, Plus, ElMessageBox, MoreFilled, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown, ElConfigProvider },
    data() {
        return {
            page: 1,
            pageSize: 10,
            total: 0,
            addVisiable: false,
            list: [],
            fullscreenLoading: false,
            nameValue: "",
            active: true,
        };
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    computed: {},
    mounted() {
        this.getList()
    },
    methods: {
        tableRowClassName({ row, rowIndex }) {
            return rowIndex % 2 === 1 ? 'warning-row' : '';
        },
        headerCellStyle() {
            return {
                background: '#f2f2f2',
            };
        },
        tableRowStyle({ row, rowIndex }) {
            if (rowIndex % 2 === 1) {
                return {
                    background: '#F5F5F5',
                };
            }
        },

        changePageSize(size) {
            this.pageSize = size;
            this.getList();
        },
        changeCurrentPage(page) {
            this.page = page;
            this.getList();
        },
        parentHandle() {
            this.addVisiable = false
        },
        reload() {
            this.getList()
        },

        getList() {
            httpService("/javaApi/materialCategories/list/" + this.page + "/" + this.pageSize, { name: this.nameValue }, "get").then((data) => {
                console.log(data);
                if (data.list) {
                    this.total = data.total
                    this.list = data.list
                }
            });
        },
        addHandle() {
            this.$refs.addMedicalProductClassify.flag = true
            this.$refs.addMedicalProductClassify.title = "新建物资分类"
        },
        editHandle(id) {
            this.$refs.addMedicalProductClassify.flag = true
            this.$refs.addMedicalProductClassify.title = "修改物资分类"
            this.$refs.addMedicalProductClassify.queryById(id)
        },
        importHandle(id) {
            this.$refs.importFileView.flag = true
            this.$refs.importFileView.url = "/javaApi/materialCategories/importExcel"
            // this.$refs.importFileView.queryById(id)
        },
        delHandle(id) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService(
                        "/javaApi/materialCategories/deleteById",
                        "id=" + id,
                        "post"
                    ).then((data) => {
                        if (data.code == 200) {
                            ElMessage.success("删除成功");
                            this.getList();
                        } else {
                            ElMessage.error("删除失败，请重试！");
                        }
                    });
                })
                .catch(() => { });
        },
        exportHandle() {
            this.fullscreenLoading = true
            httpService(
                "/javaApi/materialCategories/exportExcel", {}, "get"
            ).then((data) => {
                this.fullscreenLoading = false
                if (data.code == 200) {
                    ElMessage.success("导出成功");
                    // window.open("http://192.168.9.20" + data.message, "_blank")
                    window.open(data.message, "_blank")
                } else {
                    ElMessage.error("导出失败，请重试！");
                }
            });
        },

    },
};
</script>
<style scoped>
* {
    padding: 0;
    margin: 0;
}

.flex {
    display: flex;
    align-items: center;
}

.container {
    width: calc(100vw - 30px);
    height: calc(100vh - 30px);
    padding: 15px 15px;
    background-color: #EEF7FB;
}

.main {
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
}

.header {
    height: 35px;
    /* background-color: chocolate; */
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header_btn {
    /* width: 99px; */
    padding: 0 10px;
    height: 32px;
    background-color: #6F72FF;
    border-radius: 5px;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    margin-right: 15px;
    cursor: pointer;
}

.header_btn img {
    width: 17px;
    height: 18px;
    margin-right: 5px;
}

.serachBox {
    color: #666666;
    font-size: 14px;
    width: 333px;
    height: 36px;
    border: 1px solid #D0D0D0;
    box-sizing: border-box;
    border-radius: 20px;
}

.serachBox .flex {
    justify-content: center;
    border-right: 1px solid #D0D0D0;
    margin-right: 10px;
    padding: 0 5px 0 15px;
    color: #666666;
    cursor: pointer;
}

.serachBox input {
    height: calc(100% - 4px);
    border: none;
    flex: 1;
    outline: none;
}

.serachBox button {
    width: 59px;
    height: 30px;
    border-radius: 15px;
    border: none;
    background-color: #6F72FF;
    color: #fff;
    font-size: 14px;
    margin-right: 2px;
}


.borderBox {
    height: calc(100% - 50px);
    border: 1px solid #DFDFDF;
    border-radius: 5px;
    box-sizing: border-box;
    margin-top: 15px;
}

.borderTop {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.workList {
    display: flex;
}

.workList p {
    color: #666;
    font-size: 14px;
    margin-left: 20px;
}

.workList p span {
    color: #6F72FF;
}

.borderTop .flex {
    margin-right: 20px;
}

.borderTop_btn {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #666666;
    margin-left: 40px;
    cursor: pointer;
    color: #6F72FF;
}

.header_icon {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table_box {
    width: calc(100vw - 283px);
    height: calc(100% - 53px);
    display: flex;
    align-content: flex-start;
    flex-wrap: wrap;
    overflow-y: auto;
    /* background-color: brown; */
}


.rotate {
    transform: rotate(90deg);
}


.el-scrollbar__bar {
    z-index: 11;
    overflow-x: hidden;
    position: sticky;
}

.el-table.el-table--border {
    overflow: unset;
}


.pageBox {
    background-color: #f6f6f6;
    padding: 5px 0;
    border-top: 1px solid #e7e7e7;
    border-radius: 0 0 5px 5px;
}

.el-pagination {
    margin-left: 10px;
}

.pageBox {
    justify-content: space-between;
}

.pageBox .flex {
    color: #666;
    font-size: 14px;
    margin-right: 10px;
}

.pageBox .flex p {
    color: #666;
    font-size: 14px;
    margin-right: 20px;
}


.tabBox {
    width: 270px;
    min-height: 156px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 2px 5px 10px hsla(0, 0%, 0%, 0.09);
    margin-left: 18px;
    margin-top: 20px;
}

.tabHeader {
    justify-content: space-between;
    padding: 0 21px 0 18px;
    height: 35px;
    background: linear-gradient(to right, rgba(66, 139, 246, 0.08), rgba(22, 124, 238, 0));
    color: #000000;
    font-size: 14px;
    font-weight: bold;
}

.tabHeader img {
    width: 20px;
    height: 21px;
}

.tab_row {
    padding: 15px 20px 15px 17px;
    flex: 1;
}

.tab_row .flex {
    justify-content: space-between;
}

.tabName {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #8595A5;
}

.tabName span {
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #A7B6C5;
    margin-right: 7px;
}

.tabContent {
    color: #000000;
    font-size: 14px;
    width: calc(100% - 60px);
}

.tab_btnBox {
    padding: 0 17px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tab_btnBox button {
    width: 110px;
    height: 35px;
    border-radius: 5px;
    color: #6F72FF;
    font-size: 14px;
}

.editBtn {
    background-color: #ECECFF;
    border: none;
}

.detailBtn {
    border: 1px solid #DBE0E4;
    background-color: #fff;
}

.header_l .flex p {
    margin: 0 5px;
    white-space: nowrap;
}

.edit_btn {
    background-color: transparent;
    color: #007EFF;
    border: none;
}

.del_btn {
    background-color: transparent;
    color: #FF0000;
    border: none;
}

.v-enter-active,
.v-leave-active {
    transition: opacity 0.5s ease;
}

.v-enter-from,
.v-leave-to {
    opacity: 0;
}


.slide-up-enter-active,
.slide-up-leave-active {
    transition: all 0.25s ease-out;
}

.slide-up-enter-from {
    opacity: 0;
    transform: translateY(30px);
}

.slide-up-leave-to {
    opacity: 0;
    transform: translateY(-30px);
}
</style>